<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <!-- 移动端视口说明 -->
		<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">

		<title><?php echo C('WEB_TITLE');?></title>

		<link rel="stylesheet" href="/Public/css/common.css"/>

		<link rel="stylesheet" href="/Public/js/layui/css/layui.css"/>

        <link rel="stylesheet prefetch" href="/Public/js/photoswipe/photoswipe.css">

        <link rel="stylesheet prefetch" href="/Public/js/photoswipe/default-skin/default-skin.css">

		<link rel="stylesheet" href="/Public/mobile/css/crm-mobile-terminal.css"/>
		<link rel="stylesheet" href="/Public/js/jeDate/skin/jedate.css">
		<link rel="stylesheet" href="/Public/js/mobile-date/mobile-date.css">
		<link rel="stylesheet" href="/Public/js/mobileSelect/mobileSelect.css">

        <link rel="stylesheet" href="<?php echo C('MOBILE_ICON_HTTP');?>"/>

		<script type="text/javascript" >

			const moduleName = "<?php echo (MODULE_NAME); ?>";

		</script>

		<script type="text/javascript" src="/Public/js/jquery-1.9.1.min.js"></script>

		<script type="text/javascript" src="/Public/js/cookie/jquery.cookie.js"></script>

		<script type="text/javascript" src="/Public/js/lang/<?php echo (getStrToLower(cookie('think_language'))); ?>.js"></script>

		<script type="text/javascript" src="/Public/js/layer/layer.js"></script>

		<script type="text/javascript" src="/Public/js/layui/layui.js"></script>

		<script type="text/javascript" src="/Public/js/WeChat/wechatglobal.js"></script>

		<script type="text/javascript" src="/Public/js/WeChat/wechatupload.js"></script>

		<script type="text/javascript" src="/Public/js/photoswipe/photoswipe.min.js"></script>

		<script type="text/javascript" src="/Public/js/photoswipe/photoswipe-ui-default.min.js"></script>

        <script type="text/javascript" src="/Public/js/WeChat/iscroll.js"></script>

		<script type="text/javascript" src="/Public/js/mobile-date/mobile-date.js"></script>
		
		<script type="text/javascript" src="/Public/js/jeDate/src/jedate.js"></script>
		
		<script type="text/javascript" src="/Public/mobile/js/crm-window.js"></script>
		
		<script type="text/javascript" src="/Public/js/feeldesk-slide.js"></script>

		<script type="text/javascript" src="/Public/js/photoswipe/photohtml.js"></script>

		<style type="text/css">

            body{background-color: #fafafa}

        </style>

		<script type="text/javascript" src="/Public/js/uni.webview.1.5.2.js"></script>

		<script type="text/javascript">

			//整合版：当前页为首页发送消息给整合系统并更改页面样式
			if(self!=top)
			{
				var isIframe=true;
			}

			var isFeelecApp = false;

			if(isIframe)
			{
				document.addEventListener("UniAppJSBridgeReady", function ()
				{
					uniPostHome();
				});
			}

			document.addEventListener('UniAppJSBridgeReady', function()
			{
				uni.getEnv(function(res)
				{
					if (res.plus)//res.h5
					{
						isFeelecApp = true;

						uniPostHome();
					}
				});
			});

			function uniPostHome()
			{
				var think_controller = "<?php echo (CONTROLLER_NAME); ?>";
				var think_action = "<?php echo (ACTION_NAME); ?>";

				if(think_controller+"/"+think_action == "Index/index")
				{
					uni.postMessage({
						data: {
							isHome: true
						}
					});
				}
				else
				{
					uni.postMessage({
						data: {
							isHome: false
						}
					});
				}
			}

		</script>

	</head>

    <body>



<div class="feeldesk" id="formWrapper">

    <header>

        <div class="menu-header">

            <a href="javascript:history.go(-1)" class="iconfont icon-back-left back"></a>

            <div class="header-title"><?php echo L('ADD_CONTACT_RECORD');?></div>

            <a href="javascript:" class="header-right" id="submitForm"><?php echo L('COMPLETE');?></a>

        </div>

    </header>

    <div class="feeldesk-main no-footer-main pd0">

        <?php if(($sourcetype) == "clue"): ?><form action="<?php echo U('Customer/create_follow',['id'=>encrypt($clue_id,'CLUE'),'detailtype'=>encrypt($detailtype,'CLUE'),'sourcetype'=>$sourcetype]);?>" id="feeldeskForm" method="post" class="layui-form">

        <?php else: ?>

            <?php if(($sourcetype) == "opportunity"): ?><form action="<?php echo U('Customer/create_follow',['id'=>encrypt($opportunity_id,'OPPORTUNITY'),'detailtype'=>encrypt($detailtype,'OPPORTUNITY'),'sourcetype'=>$sourcetype]);?>" id="feeldeskForm" method="post" class="layui-form">

                <?php else: ?>

                <form action="<?php echo U('Customer/create_follow',['id'=>encrypt($customer_id,'CUSTOMER'),'detailtype'=>encrypt($detailtype,'CUSTOMER'),'sourcetype'=>$sourcetype]);?>" id="feeldeskForm" method="post" class="layui-form"><?php endif; endif; ?>

            <div class="feeldesk-form pd5">

                <div class="feeldesk-form-item">

                    <div class="feeldesk-form-block">

                        <span class="red required-icon">*</span>

                        <textarea name="follow[content]" class="feeldesk-input feeldesk-textarea" placeholder="<?php echo L('ENTER_CONTACT_RECORD');?>" id="follow_content"></textarea>

                    </div>

                </div>

                <?php if(($sourcetype) != "clue"): if(($sourcetype) != "opportunity"): ?><div class="feeldesk-form-item <?php if(empty($customer_id)): ?>mb0<?php endif; ?>" >

                            <div class="feeldesk-form-block">

                                <input type="hidden" name="follow[customer_id]" value="<?php echo ($customer_id); ?>" id="sCustomerInput" />

                                <?php if(empty($customer_id)): ?><span class="sCustomerName" id="sCustomerName"></span>

                                    <span class="selectCustomerBtn" id="selectCustomer"> + <?php echo L('SELECT_CUSTOMER');?></span><?php endif; ?>

                            </div>

                        </div>

                        <?php if(empty($customer_id)): ?><div class="feeldesk-form-item" >

                                <div class="feeldesk-form-block">

                                    <input type="hidden" name="follow[clue_id]" value="<?php echo ($clue_id); ?>" id="sClueInput" />

                                    <span class="sCustomerName" id="sClueName"></span>

                                    <span class="selectCustomerBtn" id="selectClue"> + <?php echo L('SELECT_CLUE');?></span>

                                </div>

                            </div><?php endif; ?>

                        <div class="feeldesk-form-item <?php if(empty($contacter)): ?>hidden<?php endif; ?>" >

                            <div class="feeldesk-form-block">

                                <select name="follow[contacter_id]" id="ContacterList" lay-filter="ContacterList">

                                    <?php if(is_array($contacter)): $i = 0; $__LIST__ = $contacter;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["contacter_id"]); ?>" ><?php echo ($vo["detail"]["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>

                                </select>

                            </div>

                        </div>

                    <?php else: ?>

                        <input type="hidden" name="follow[opportunity_id]" value="<?php echo ($opportunity_id); ?>" /><?php endif; ?>

                <?php else: ?>

                    <div class="feeldesk-form-item" >

                        <div class="feeldesk-form-block">

                            <input type="hidden" name="follow[clue_id]" value="<?php echo ($clue_id); ?>" />

                        </div>

                    </div><?php endif; ?>

                <div class="feeldesk-form-item">

                    <div class="feeldesk-form-block">

                        <select name="follow[cmncate_id]" lay-filter="getCmncateReply">

							<option value=""><?php echo L('COMMUNICATION_TYPE');?></option>

                            <?php if(is_array($cmncate)): $i = 0; $__LIST__ = $cmncate;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["cmncate_id"]); ?>" ><?php echo ($vo["cmncate_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>

                        </select>

                    </div>

                </div>

				<div class="feeldesk-form-item hidden">

                    <div class="feeldesk-form-block">

                        <select name="follow[reply_id]" id="cmncate_reply" lay-filter="ReplyContent">

                            <option value=""><?php echo L('CUSTOM_REPLY');?></option>

                        </select>

                    </div>

                </div>

                <div class="feeldesk-form-item">

                    <div class="feeldesk-form-block">

                        <input type="text" name="follow[nextcontacttime]" value="" placeholder="<?php echo L('NEXT_CONTACT_TIME');?>" id="follow-date" class="feeldesk-input" readonly />

                        <script type="text/javascript">

                            $(function()
                            {
                                var minDate = "<?php echo getDates(NOW_TIME,2);?>";

                                jeDate("#follow-date",{
                                    minDate:minDate,              //最小日期
                                    maxDate:"2099-12-31 23:59:59",              //最大日期
                                    method:{
                                        choose:function (params) {

                                        }
                                    },
                                    format: "YYYY-MM-DD hh:mm:ss"
                                });
                            })

                        </script>

                    </div>

                </div>

                <div class="feeldesk-form-item relative">

                    <div class="feeldesk-form-block">

                        <!-- 单选 -->
                        <div class="feeldesk-input feeldesk-form-check radio name-radio"><span><?php echo L('WHETHER_SAVE_FOLLOW_UP_TEMPLATE');?></span><i class="feeldesk-edge"></i></div>

                        <ul class="feeldesk-option-panel radioPanel hidden">

                            <input type="hidden" name="reply" value=""/>

                            <li data-name="<?php echo L('YES');?>" data-value="1">

                                <div class="feeldesk-option">

                                    <span class="feeldesk-option-title"><?php echo L('YES');?></span>

                                    <span class="iconfont icon-check"></span>

                                </div>

                            </li>

                            <li data-name="<?php echo L('NO');?>" data-value="2">

                                <div class="feeldesk-option">

                                    <span class="feeldesk-option-title"><?php echo L('NO');?></span>

                                    <span class="iconfont icon-check"></span>

                                </div>

                            </li>

                        </ul>

                    </div>

                </div>

                <div class="feeldesk-form-item relative">

                    <div class="feeldesk-form-block">

                        <button type="button" class="layui-btn layui-btn-primary uploadFile"><i class="layui-icon"></i><?php echo L('UPLOAD_ATTACHMENTS');?></button>

                        <ul id="attachments" class="attach-item mt10"></ul>

                    </div>

                </div>

            </div>

        </form>

    </div>

</div>

<div class="sCustomer" id="sCustomer">

	<div class="sCustomer-shade"></div>

	<div class="sCustomer-content">

		<header>

			<a href="javascript:" class="sCustomer-cancel" id="sCustomerCancel"><?php echo L('CANCEL');?></a>

			<div class="sCustomer-search">

				<i class="iconfont icon-search"></i>

				<input type="text" name='' id="sCustomerSearch" placeholder="<?php echo L('CLIENT_NAME');?>">

			</div>

			<a href="javascript:" class="sCustomer-ensure" id="sCustomerDone"><?php echo L('COMPLETE');?></a>

		</header>

		<main id="sCustomerItem"><div class="no-match"><?php echo L('NO_MATCH');?></div></main>

	</div>

</div>

<script>

	var no_more = "<?php echo L('NO_MORE');?>";

	var selectActionUrl = '/<?php echo (CONTROLLER_NAME); ?>/<?php echo (ACTION_NAME); ?>';

	var selectAction = '<?php echo (ACTION_NAME); ?>';

	$('#selectCustomer').click(function()
	{
		var company_id = '<?php echo ($mobile["company_id"]); ?>';

		$('#sCustomer').toggleClass('sCustomer-show');

		if($('.sCustomer-show').length > 0)
		{
			togetCustomerList();
		}

		$('#sCustomerCancel').unbind('click').on('click',function()
		{
			$('#sCustomer').toggleClass('sCustomer-show');
		});

		$('#sCustomerSearch').keyup(function ()
		{
			var value = $(this).val();

			var sCustomer = $('.sCustomer-item');

			var sCustomerItem = $('#sCustomerItem');

			if(value)
			{
				togetCustomerList(value);
			}
			else
			{
				togetCustomerList();
			}
		});
	})

	function togetCustomerList(keyword='')
	{
		$("#sCustomerItem").empty();

		layui.use('flow', function ()
		{
			var flow = layui.flow;

			flow.load(
			{
				elem: '#sCustomerItem',
				end: no_more,
				done: function (page, next)
				{
					$.post("<?php echo U('AjaxRequest/getCustomerList');?>?request=sCustomer&keyword="+keyword+"&p=" + page, function (data)
					{
						var lis = [];

						var item = '';

						$.each(data.data,function(k,v)
						{
							item +="<div class='sCustomer-item' data-value='"+v.customer_id+"' data-name='"+v.detail.name+"'>" +
								"<span class='ticket-title ellipsis'>"+ v.detail.name+"</span>" +
								"<span class='iconfont icon-check'></span></div>"
						});

						lis.push(item);

						next(lis.join(''), page < data.pages);

						$('.sCustomer-item').unbind('click').on('click',function()
						{
							$(this).find('span.iconfont').addClass('icon-radio-checked').parent().siblings().find('span').removeClass('icon-radio-checked');
						})

					},'JSON');
				}
			});
		});

		$('#sCustomerDone').unbind('click').on('click',function()
		{
			var customer_id = $('.sCustomer-item').find('span.icon-radio-checked').parent().data('value');

			var customer_name = $('.sCustomer-item').find('span.icon-radio-checked').parent().data('name');

			$('#sCustomerInput').val(customer_id);

			$('#sCustomerName').html(customer_name);

			if(selectAction == 'create_follow')
			{
				$.ajax(
				{
					url:"<?php echo U('AjaxRequest/getContacter');?>",

					type:'POST',

					async: false,

					data:{'customer_id':customer_id},

					datatype:'json',

					success:function(data)
					{
						$('#ContacterList').html(data.html);

						layui.use('form', function() {

							var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

							form.render('select');

						});

						$('#ContacterList').parents('.feeldesk-form-item').removeClass('hidden');
					},
					error:function()
					{
					   //layer.msg('保存排序异常');
					}
				});
			}

			if($.inArray(selectActionUrl,['/Account/create','/Receipt/create','/Invoice/create']) != -1)
			{
				$.ajax({
					url:"<?php echo U('AjaxRequest/getContract');?>",
					type:'POST',
					async: false,
					data:{'customer_id':customer_id,'type':'option'},
					datatype:'json',
					success:function(data)
					{
						$('#contractList').html(data.html);

						layui.use('form', function() {

							var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

							form.render('select');

						});
					}
				});

				if(selectActionUrl == '/Invoice/create')
				{
					$.ajax({
						url:"<?php echo U('AjaxRequest/getCustomerInvoiceInfo');?>",
						type:'POST',
						async: false,
						data:{'customer_id':customer_id},
						datatype:'json',
						success:function(data)
						{
							$('#InvoiceInfoList').html(data.html);

							layui.use('form', function() {

								var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

								form.render('select');

							});
						}
					});
				}
			}

			/*if(selectActionUrl == '/Order/create')
			{
				$.ajax({
					url:"<?php echo U('AjaxRequest/getContract');?>",
					type:'POST',
					async: false,
					data:{'customer_id':customer_id},
					datatype:'json',
					success:function(data)
					{
						$('#selectContract span').html('<?php echo L('ASSOCIATED_CONTRACT');?>');

						$('#sContractList').hide();

						$('#sContractList').html(data.html);

						checkboxClick();

					},
					error:function()
					{

					}
				});
			}*/

			if(selectActionUrl == '/Contract/create')
			{
				$.ajax({
					url:"<?php echo U('AjaxRequest/getOpportunity');?>",
					type:'POST',
					async: false,
					data:{'customer_id':customer_id},
					datatype:'json',
					success:function(data)
					{
						$('#sOpportunitySelect').html(data.html);

						layui.use('form', function() {

							var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

							form.render('select');

						});
					},
					error:function()
					{

					}
				});
			}

			$('#sCustomer').toggleClass('sCustomer-show');
		})
	}

	function checkboxClick()
	{
		$(".checkbox").unbind('click').on('click',function()
		{
			var checkbox = $(this);

			$(this).toggleClass('feeldesk-form-checked').next('.feeldesk-option-panel').slideToggle('fast');

			$(this).parents('.feeldesk-form-item').siblings().find('.feeldesk-input').removeClass('feeldesk-form-checked').next('.feeldesk-option-panel').slideUp('fast');

			$(".checkboxPanel").find('li').on('click',function()
			{
				var value = $(this).data('value');

				$(this).find('span.iconfont').toggleClass('icon-checkbox-checked');

				var oldValue = checkbox.find('span').text();

				var content = '';

				if($(this).find('span.iconfont').hasClass('icon-checkbox-checked'))
				{
					$(this).find("input").prop('checked',true);

					content = addContent(oldValue,value);
				}
				else
				{
					$(this).find("input").prop('checked',false);

					content = removeContent(oldValue,value);
				}

				$(this).parent('.checkboxPanel').prev('.checkbox').find('span').text(content);
			});
		});
	}

</script>


<div class="sClue" id="sClue">

	<div class="sClue-shade"></div>

	<div class="sClue-content">

		<header>

			<a href="javascript:" class="sClue-cancel" id="sClueCancel"><?php echo L('CANCEL');?></a>

			<div class="sClue-search">

				<i class="iconfont icon-search"></i>

				<input type="text" name='' id="sClueSearch" placeholder="<?php echo L('CLIENT_NAME');?>">

			</div>

			<a href="javascript:" class="sClue-ensure" id="sClueDone"><?php echo L('COMPLETE');?></a>

		</header>

		<main id="sClueItem"><div class="no-match"><?php echo L('NO_MATCH');?></div></main>

	</div>

</div>

<script>

	var no_more = "<?php echo L('NO_MORE');?>";

	var selectActionUrl = '/<?php echo (CONTROLLER_NAME); ?>/<?php echo (ACTION_NAME); ?>';

	var selectAction = '<?php echo (ACTION_NAME); ?>';

	$('#selectClue').click(function()
	{
		var company_id = '<?php echo ($mobile["company_id"]); ?>';

		$('#sClue').toggleClass('sClue-show');

		if($('.sClue-show').length > 0)
		{
			togetClueList();
		}

		$('#sClueCancel').unbind('click').on('click',function()
		{
			$('#sClue').toggleClass('sClue-show');
		});

		$('#sClueSearch').keyup(function ()
		{
			var value = $(this).val();

			if(value)
			{
				togetClueList(value);
			}
			else
			{
				togetClueList();
			}
		});
	})

	function togetClueList(keyword='')
	{
		$("#sClueItem").empty();

		layui.use('flow', function ()
		{
			var flow = layui.flow;

			flow.load(
			{
				elem: '#sClueItem',
				end: no_more,
				done: function (page, next)
				{
					$.post("<?php echo U('AjaxRequest/getClueList');?>?request=sClue&keyword="+keyword+"&p=" + page, function (data)
					{
						var lis = [];

						var item = '';

						$.each(data.data,function(k,v)
						{
							item +="<div class='sClue-item' data-value='"+v.clue_id+"' data-name='"+v.detail.name+"'>" +
								"<span class='ticket-title ellipsis'>"+ v.detail.name+"</span>" +
								"<span class='iconfont icon-check'></span></div>"
						});

						lis.push(item);

						next(lis.join(''), page < data.pages);

						$('.sClue-item').unbind('click').on('click',function()
						{
							$(this).find('span.iconfont').addClass('icon-radio-checked').parent().siblings().find('span').removeClass('icon-radio-checked');
						})

					},'JSON');
				}
			});
		});

		$('#sClueDone').unbind('click').on('click',function()
		{
			var clue_id = $('.sClue-item').find('span.icon-radio-checked').parent().data('value');

			var clue_name = $('.sClue-item').find('span.icon-radio-checked').parent().data('name');

			$('#sClueInput').val(clue_id);

			$('#sClueName').html(clue_name);

			$('#sClue').toggleClass('sClue-show');
		})
	}

</script>